﻿using System.Linq;
using StructureMap;
using System;
using System.Collections.Generic;
using Caliburn.Micro;
using Yapdb.Domain.Infrastructure;

namespace Yapdb.WinGui.Infrastructure
{
	
	public class AppBootstrapper : Bootstrapper<IShell>
	{
		private IContainer _container;

		/// <summary>
		/// By default, we are configured to use MEF
		/// </summary>
		protected override void Configure()
		{
		    _container = new Container(x =>
		                                  {
		                                      x.AddRegistry(new CaliburnRegistry());
                                              x.AddRegistry(new DomainRegistry());
		                                  });

		}

		protected override object GetInstance(Type serviceType, string key)
		{
            return string.IsNullOrWhiteSpace(key) ? _container.GetInstance(serviceType) : _container.GetInstance(serviceType, key);
		}

		protected override IEnumerable<object> GetAllInstances(Type serviceType)
		{
		    return _container.GetAllInstances(serviceType).Cast<object>();
		}

	    protected override void BuildUp(object instance)
		{
            _container.BuildUp(instance);
		}
	}
}